package com.bsy.common.permission

import android.content.Context
import android.content.res.Resources.NotFoundException
import com.bsy.common.R
/**
 * Created by Sincerity on 2024/3/29.
 * Copyright
 * 描述：
 */
object PermissionDescriptionConvert {
    /**
     * 获取权限描述
     */
    fun getPermissionDescription(context: Context, permissions: List<String?>?): String {
        val stringBuilder = StringBuilder()
        val permissionNames = PermissionNameConvert.permissionsToNames(context, permissions)
        for (permissionName in permissionNames) {
            stringBuilder.append(permissionName)
                .append(context.getString(R.string.common_permission_colon))
                .append(permissionsToDescription(context, permissionName))
                .append("\n")
        }
        return stringBuilder.toString().trim { it <= ' ' }
    }

    /**
     * 将权限名称列表转换成对应权限描述
     */
    private fun permissionsToDescription(context: Context, permissionName: String?): String {
        return when (permissionName) {
            //存储权限描述
            context.getString(R.string.common_permission_image_and_video),
            context.getString(R.string.common_permission_all_file_access),
            context.getString(R.string.common_permission_storage) ->
                context.getString(R.string.common_permission_storage_desc)
            //位置权限
            context.getString(R.string.common_permission_location),
            context.getString(R.string.common_permission_location_background) ->
                context.getString(R.string.common_permission_local_desc)
            //拨打电话
            context.getString(R.string.common_permission_call_logs),
            context.getString(R.string.common_permission_phone) ->
                context.getString(R.string.common_permission_call_desc)
            //相机
            context.getString(R.string.common_permission_camera) ->
                context.getString(R.string.common_permission_camera_desc)

            else -> throw NotFoundException("未定义的权限描述")
        }
    }
}